package com.cy.event;

import com.alibaba.fastjson.JSONObject;
import com.cy.entity.Event;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @Author: cy
 * @Date: 2022/02/05/21:17
 * @Description:   kafka消息生产者
 */
@Component
public class EventProducer {

    @Resource
    private KafkaTemplate kafkaTemplate;

    //处理事件
    public void fireMessage(Event event){
        //将事件发布到指定的主题
        kafkaTemplate.send(event.getTopic(), JSONObject.toJSONString(event));
    }
}
